import { Component } from '@angular/core';
import { OnInit } from '@angular/core/src/metadata/lifecycle_hooks';
import { AuthService } from './service/auth.service';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{
  title = '个人日程管理';

  public isLogin: boolean = false;
  constructor(public http: HttpClient, public authService: AuthService) {
    console.log(this.isLogin)
   }

  async ngOnInit() {
    let token = localStorage.getItem("token");
    if (!token) {
      this.isLogin = false;
      return;
    }
    try {
      console.log("begin...")
      this.isLogin = await this.authService.ping(token);
      console.log("end....")
    } catch (err) { 
      if (err.code == 403 && /登录已失效/.test(err.msg)) { 
        this.isLogin = false;
      }
    }
  }
}
